﻿
using Maticsoft.BLL;
using Maticsoft.DBUtility;
using Maticsoft.Model;
using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class WebPage_User : SystemBBasePage
{

    private Maticsoft.BLL.Order orderlist = new Maticsoft.BLL.Order();

    public Maticsoft.BLL.UserInfo user = new Maticsoft.BLL.UserInfo();


    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "user";
        if (!this.Page.IsPostBack)
        {
            this.selectedvalue();
            this.PdbShow();
        }
        if (base.Request.HttpMethod == "POST")
        {
            this.PdbShow();
        }
    }

    protected void pager_PageChanged(object sender, EventArgs e)
    {
        this.PdbShow();
    }

    private void PdbShow()
    {
        int num;
        string where = " 1=1 ";
        if (this.txtuser.Text != "")
        {
            where = where + " and Username like '" + this.txtuser.Text + "%'";
        }
        if (this.txtemail.Text != "")
        {
            where = where + " and Email like '" + this.txtemail.Text + "%'";
        }
        if ((this.ddlcity.SelectedValue != "") && (this.ddlcity.SelectedValue != "0"))
        {
            where = where + " and City_id=" + this.ddlcity.SelectedValue;
        }
        StringBuilder builder = new StringBuilder();
        StringBuilder builder2 = new StringBuilder();
        builder2.Append("<tr >");
        builder2.Append("<th width='20px'>ID</td>");
        builder2.Append("<th width='200px'>Email/用户名</td>");
        builder2.Append("<th width='90px' nowrap>姓名/城市</td>");
        builder2.Append("<th width='40px'>余额</td>");
        builder2.Append("<th width='40px'>邮编</td>");
        builder2.Append("<th width='120px'>注册时间</td>");
        builder2.Append("<th width='80px'>购买次数</td>");
        builder2.Append("<th width='100px'>联系电话</td>");
        builder2.Append("<th width='120px'>操作</td>");
        builder2.Append("</tr>");
        this.Literal3.Text = builder2.ToString();
        StringBuilder builder3 = new StringBuilder();
        DataSet set = DbHelperSQL.Page(50, this.pager.CurrentPageIndex, "[User]", where, "  Create_time desc", "*", out num);
        if (((set != null) && (set.Tables.Count > 0)) && (set.Tables[0].Rows.Count > 0))
        {
            for (int i = 0; i < set.Tables[0].Rows.Count; i++)
            {
                DataRow row = set.Tables[0].Rows[i];
                Maticsoft.Model.Category model = new Maticsoft.BLL.Category().GetModel(int.Parse(row["City_id"].ToString()));
                if ((i % 2) != 0)
                {
                    builder3.Append("<tr  id='team-list-id-" + row["id"] + "'>");
                }
                else
                {
                    builder3.Append("<tr class=\"alt\"  id='team-list-id-" + row["id"] + "'>");
                }
                builder3.Append("<td>" + row["Id"].ToString() + "</td>");
                builder3.Append("<td>" + row["Email"].ToString() + "<br/>" + row["Username"].ToString() + "</td>");
                if (model != null)
                {
                    builder3.Append("<td>" + row["Realname"].ToString() + "<br/>" + model.Name + "</td>");
                }
                else
                {
                    builder3.Append("<td>" + row["Realname"].ToString() + "<br/>全部城市</td>");
                }
                builder3.Append("<td><span class='currency'>" + row["Money"].ToString() + "</span></td>");
                builder3.Append("<td>" + row["Zipcode"].ToString() + "</td>");
                builder3.Append("<td>" + row["Sns"].ToString() + "<br/>" + row["Create_time"].ToString() + "</td>");
                builder3.Append("<td>" + this.orderlist.GetModelList("State='pay' and User_id=" + row["id"].ToString()).Count + "</td>");
                builder3.Append("<td>" + row["Mobile"] + "</td>");
                builder3.Append("<td class='op'>");
                builder3.Append("<a class='ajaxlink' href='/ajax/manage.aspx?action=userview&Id=" + row["Id"].ToString() + "'>详情</a>｜");
                builder3.Append("<a href='User_Bianji.aspx?id=" + row["Id"].ToString() + "'>编辑</a>");
                builder3.Append("</td>");
                builder3.Append("</tr>");
            }
        }
        this.pager.RecordCount = num;
        this.Literal1.Text = builder3.ToString();
    }

    private void selectedvalue()
    {
        StringBuilder builder = new StringBuilder();
        DataTable cityList = base.CityList;
        this.ddlcity.Items.Insert(0, new ListItem("全部城市", "0"));
        for (int i = 0; i < cityList.Rows.Count; i++)
        {
            builder.Append("<option value='" + cityList.Rows[i]["id"].ToString() + "' >" + cityList.Rows[i]["Name"].ToString() + "</option>");
            this.ddlcity.Items.Add(new ListItem(cityList.Rows[i]["Name"].ToString(), cityList.Rows[i]["id"].ToString()));
        }
    }
}

